# -*- coding: utf-8 -*-
from calctest1 import calctest1
from flask import Flask, render_template, request, url_for, redirect, flash

app = Flask(__name__)
app.config["SECRET_KEY"]="secret123"


def judge_answer(ans1, ans2)->str:
    if ans1==ans2:
        return "你真棒！"
    else:
        return "不对哦，答案是："+ans2
@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        question = request.form['question']
        answer = request.form['answer']
        answer1 = calctest1(question)
        flash('info transmitted')
        return render_template('index.html', result=judge_answer(answer, answer1))
    return render_template('index.html', result="")
